package com.hy.study.conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.apache.log4j.Logger;
import java.util.Objects;

/**
 * @author huyong
 * @date 2024 年 01 月 03 日 9:34: 00
 */
public class TestConditional implements Condition {
    private static Logger log = Logger.getLogger(TestConditional.class.getName());
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        // 当testAspect 组件加载完毕之后加载 testLog
        if (Objects.requireNonNull(conditionContext.getBeanFactory()).containsBean("testAspect")) {
            log.info("判断testAspect bean 是否加载完毕");
            return true;
        }
        return false;
    }
}
